AreaTrigger Properties
The AreaTrigger class represents area triggers in the game world. These are often used for environmental effects, spell areas, or interactive zones.
AreaTriggers are objects in the game world that can be interacted with or trigger effects when players enter or leave their area.
AreaTrigger Methods
These methods provide information about the AreaTrigger's properties and position in the game world.
id()
Returns the unique identifier of the AreaTrigger.
local areaTriggerId = areaTrigger:id()
print("AreaTrigger ID:", areaTriggerId)
Returns: number
guid()
Returns the Global Unique Identifier (GUID) of the AreaTrigger.
local areaGUID = areaTrigger:guid()
print("AreaTrigger GUID:", areaGUID)
Returns: string
rotation()
Returns the rotation of the AreaTrigger in the game world.
local rotation = areaTrigger:rotation()
print("AreaTrigger rotation:", rotation)
Returns: number
position()
Returns the current position of the AreaTrigger in the game world.
local pos = areaTrigger:position()
print("AreaTrigger position:", pos.x, pos.y, pos.z)
Returns: table
with x
, y
, and z
coordinates
Distance Calculation Methods
These methods allow you to calculate distances between the AreaTrigger and other objects or coordinates in the game world.
distanceto(target, [y], [z])
Calculates the distance between the AreaTrigger and a target, accounting for combat reach if applicable.
local distance = areaTrigger:distanceto(targetUnit)
print("Distance to target:", distance)
-- Or with coordinates
local distanceToPoint = areaTrigger:distanceto(x, y, z)
print("Distance to point:", distanceToPoint)
Parameters:
target
: A Unit object or the x-coordinatey
: (optional) y-coordinate if using raw coordinatesz
: (optional) z-coordinate if using raw coordinates
Returns: number
(distance in yards)
This method subtracts the combat reach of the AreaTrigger and the target (if it's a Unit) from the raw distance.
distancetoliteral(target, [y], [z])
Calculates the literal distance between the AreaTrigger and a target, without accounting for combat reach.
local literalDistance = areaTrigger:distancetoliteral(targetUnit)
print("Literal distance to target:", literalDistance)
-- Or with coordinates
local literalDistanceToPoint = areaTrigger:distancetoliteral(x, y, z)
print("Literal distance to point:", literalDistanceToPoint)
Parameters:
target
: A Unit object or the x-coordinatey
: (optional) y-coordinate if using raw coordinatesz
: (optional) z-coordinate if using raw coordinates
Returns: number
(distance in yards)
Usage Examples
Here are some examples of how you might use these methods in your addon:
local areaTrigger = LT.AreaTrigger:New(pointerToAreaTrigger)
-- Get basic information about the AreaTrigger
print("AreaTrigger ID:", areaTrigger:id())
print("AreaTrigger GUID:", areaTrigger:guid())
-- Get the position of the AreaTrigger
local pos = areaTrigger:position()
print("AreaTrigger position:", pos.x, pos.y, pos.z)
-- Calculate distance to a player
local player = LT.Player
local distanceToPlayer = areaTrigger:distanceto(player)
print("Distance to player:", distanceToPlayer)
-- Check if a player is within a certain range of the AreaTrigger
if distanceToPlayer <= 10 then
print("Player is within 10 yards of the AreaTrigger")
end
Remember that AreaTriggers are often used for spell effects or environmental interactions. You can use these methods to determine if players or other units are within the effect range of an AreaTrigger.